package com.dunqi.gpm.shunqing.develop.widget;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;

import com.dunqi.gpm.shunqing.R;
import com.dunqi.gpm.shunqing.common.util.CommonUtil;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2017/11/18.
 */

public class ThreeInOne extends FrameLayout {

    @BindView(R.id.favorite_rb)
    DrawLeftRadioButton favoriteRb;
    @BindView(R.id.good_rb)
    DrawLeftRadioButton goodRb;
    @BindView(R.id.write_rb)
    DrawLeftRadioButton writeRb;

    int px = CommonUtil.dip2px(20);

    public ThreeInOne(@NonNull Context context) {
        this(context, null);
    }

    public ThreeInOne(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        View view = LayoutInflater.from(context).inflate(R.layout.three_in_one, this);
        ButterKnife.bind(this, view);

//        Drawable drawable1 = ContextCompat.getDrawable(context, R.mipmap.favorites_n);
        Drawable drawable1 = ContextCompat.getDrawable(context, R.drawable.develop_favarite_selector);
        drawable1.setBounds(0, 0, px, px);
        favoriteRb.setCompoundDrawables(drawable1, null, null, null);

        Drawable drawable2 = ContextCompat.getDrawable(context, R.mipmap.good_n);
//        Drawable drawable2 = ContextCompat.getDrawable(context, R.drawable.develop_good_selector);
        drawable2.setBounds(0, 0, px, px);
        goodRb.setCompoundDrawables(drawable2, null, null, null);

//        Drawable drawable3 = ContextCompat.getDrawable(context, R.mipmap.write_n);
        Drawable drawable3 = ContextCompat.getDrawable(context, R.drawable.develop_write_selector);
        drawable3.setBounds(0, 0, px, px);
        writeRb.setCompoundDrawables(drawable3, null, null, null);


    }

    public void setGoneLeft2(){
        favoriteRb.setVisibility(GONE);
        writeRb.setVisibility(VISIBLE);
        goodRb.setVisibility(GONE);
    }

    public void setOnClickListener(@Nullable OnClickListener l1, @Nullable OnClickListener l2, @Nullable OnClickListener l3) {
        favoriteRb.setOnClickListener(l1);
        goodRb.setOnClickListener(l2);
        writeRb.setOnClickListener(l3);
    }

    public boolean isLeftChecked() {
        return favoriteRb.isChecked();
    }

    public void setLeftChecked(boolean isChecked) {
        favoriteRb.setChecked(isChecked);
    }

    public void setRightText(String text) {
        writeRb.setText(text);
    }


}
